/*
 * Copyright (c) 2018.
 * This file was written by Fancyears·Milos·Malvis @connor. Any question/bug you can't post to 1243093366@qq.com.
 * ALL RIGHTS RESERVED.
 */
package org.fancyears.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.fancyears.dao.UserDao;
import org.fancyears.entity.User;
import org.fancyears.sql.BaseSQLUtil;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @author: Fancyears·Milos·Malvis
 * @CreateDate: 2018年12月6日 下午5:13:45
 * @Description:
 */

public class UserDaoImpl extends BaseSQLUtil<User> implements UserDao {
	public User selectById(User user) throws Exception {
		return super.selectOne(user);
	}

	public List<User> selectList(User user) throws Exception {
		return super.selectList(user);
	}

	/**
	 * 使用pagehelper增强的分页
	 * 
	 * @throws Exception
	 */
	@Override
	public List<User> selectListX(int start, int size) throws Exception {
		// 起始页数是从1开始而不是从0开始
		PageHelper.startPage(start, size);
		// 返回的是一个被代理后的对象，而不是List对象
		List<User> users = super.selectList(null);
		PageInfo<User> pageInfo = new PageInfo<>(users);
		return pageInfo.getList();
	}

	/**
	 * mybatis自带的分页
	 */
	public List<User> selectListX(User user, RowBounds rowBounds) {
		return super.getSession().selectList(UserDao.class.getCanonicalName() + ".selectListX", user, rowBounds);
	}

	public User selectByObj(Object user) throws Exception {
		return super.selectOne(user);
	}

	public int insert(User user) throws Exception {
		return super.insert(user);
	}

	public int insertByObj(Object user) throws Exception {
		return insert(user);
	}

	public List<User> selectByMap(Map<String, Object> params) throws Exception {
		return super.selectList(params);
	}

}
